﻿using Authentication.Configuration;
using Authentication.Model.Model;
using Common.Data.Extensions;

namespace Authentication.Data.DBConfig
{
    public class AccountRuleConfiguration : DBConfig<ApplicationAccountRule>
    {
        public AccountRuleConfiguration()
            : base(SystemConfiguration.Schema, SystemConfiguration.NamingType, SystemConfiguration.TABLE_PREFIX)
        {
            HasKey(x => new { x.ApplicationKey, x.UserName, x.ObjectId, x.RuleId });
            Property(c => c.ApplicationKey).IsRequired().HasMaxLength(36);
            Property(c => c.UserName).IsRequired().HasMaxLength(50);
            Property(c => c.ObjectId).IsRequired().HasMaxLength(50);
            Property(c => c.RuleId).IsRequired();
            Property(c => c.Active).HasMaxLength(1);


            //relationship  
            HasRequired(ad => ad.Object).WithMany(s => s.AccountRules).HasForeignKey(t => new { t.ApplicationKey, t.ObjectId });
        }
    }
}
